define(["jquery","bootstrap.datetimepicker","bootstrap.datetimepicker.cn","contextmenu","bbcare","comm/form/form","bld/app/patient/specialtyBags.servers","bld/app/patient/specialtyBags.ui","bld/app/patient/specialtyBags.event"],function($,datetimepicker,datetimepickerCn,$contextmenu,$bb,$form,$servers,$ui,$event){
	var specialtyBags = {};
	var channelId = $bb.getChannelId();
	var doctorName = JSON.parse($bb.getSessionStorage("account")).alias;

	/**
	 * 修改身高、体重、体表面积失败后的回调函数
	 */
	var ajaxChangeHeightAndWeightCallBack2 = function(data){
		$bb.toastShow(data.msg ? data.msg : "修改出错！");
		$("#height,#weight,#area").val("");
	}

	/**
	 * 修改身高、体重、体表面积成功后的回调函数
	 */
	var ajaxChangeHeightAndWeightCallBack = function(data,datas){
		$bb.toastShow("修改成功！");
		specialtyBags.init(datas);
	}

	/**
	 * 身高、体重、体表面积校验
	 */
	var validateHeightAndWeight = function(num,msg,max){
		var reg = /^-?\d+(\.\d+)?$/;
		if( !num ){
			$bb.toastShow("请输入"+ msg +"！");
			return false;
		}
		if( !reg.test(num) ){
			$bb.toastShow(msg + "请输入数字！");
			return false;
		}
		if( num <= 0 ){
			$bb.toastShow(msg + "请输入大于0的数字！");
			return false;
		}
		if( num > max ){
			$bb.toastShow(msg + "请输入小于"+max+"的数字！");
			return false;
		}
		return true;
	}

	/**
	 * 修改身高、体重、体表面积
	 */
	var onChangeBlur = function(){
		var height = Number( $("#height").val() );
		var weight = Number( $("#weight").val() );
		// 暂定最高300cm，最重300kg
		if( validateHeightAndWeight(height,"身高",300) && validateHeightAndWeight(weight,"体重",300) ){
			var area = Math.sqrt( height * weight / 3600 ).toFixed(2);
			$("#area").val(area);
			if( $(this).attr("id") == "area" ) return;
			var datas = $(this).data("datas");
			var params = {
				"oprInfo":{
					"channelId":channelId,
					"channelType":"2",
					"opType":"2",
					"opCode":"1232",
					"opNote":"【"+ doctorName +"】修改【"+ datas.info.userName +"】患者在【"+ datas.currCourse.courseName +"】疗程下的身高、体重、体表面积",
				},
				"ptDisCourseInfo":{
					"id":datas.currCourse.ptCourseId,
					"userId":datas.currScheme.userId,
					"courseHeight":height,
					"courseWeight":weight,
					"surfaceArea":area,
				}
			};
			$servers.ajaxChangeHeightAndWeight(params,ajaxChangeHeightAndWeightCallBack,ajaxChangeHeightAndWeightCallBack2,datas);
		}
	}

	/**
	 * 改变分组 ？？？未完成
	 */
	var onGroupTypeChange = function(){
		var groupType = $(this).val();
	}

	/**
	 * 警示信息查询成功后的回调函数
	 */
	var ajaxPtWarnMsgCallBack = function(data){
		var msg = data.warnMsg ? "警示：" + data.warnMsg : "";
		$("#warn").html(msg);
	}

	/**
	 * 初始化title、info
	 */
	var initUi = function(datas){
		$ui.title({
			"id":"specialtyBagsTitle",
			"stageName":datas.currStage.stageName,
			"courseName":datas.currCourse.courseName
		});
		$ui.info({
			"id":"specialtyBagsInfo",
			"info":datas.info,
			"currCourse":datas.currCourse
		});
		// 身高、体重、体表面积
		$("#height,#weight,#area").unbind("blur");
		$("#height,#weight,#area").data("datas",datas);
		$("#height,#weight,#area").blur(onChangeBlur);
		// 分组 暂时不做
		/*$("#groupType").unbind("change");
		$("#groupType").change(onGroupTypeChange);*/
		// 警示信息
		var params = {
			"userId":datas.info.userId,
            "flag":"1"
		};
		$servers.ajaxPtWarnMsg(params,ajaxPtWarnMsgCallBack);
	}

	/**
	 * 设置开始时间成功后的回调函数
	 */
	var ajaxSetStartTimeCallBack = function(data,datas){
		$bb.toastShow("初始时间设置成功！");
		// 专科袋药品表头信息查询
		$servers.ajaxMedicineInfo(datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 设置开始时间
	 */
	var onSetStartTime = function(){
		var arg = $(this).data("arg");
		var dealDate = $(this).val();
		var params = {
			"oprInfo":{
				"channelId":channelId,
				"channelType":"2",
				"opType":"2",
				"opCode":"1230",
				"opNote":"【" + doctorName + "】给【" + arg.datas.currCourse.courseName + "】疗程设置起始日期为【" + dealDate + "】",
			},
			"ptEhrEventInfo":{
				"dealDate":dealDate,
				"ptStageId":arg.datas.currStage.ptStageId,
				"ptCourseId":arg.datas.currCourse.ptCourseId,
			}
		};
		arg.dom = $(this);
		$servers.ajaxSetStartTime(params,ajaxSetStartTimeCallBack,arg);
	}

	/**
	 * 设置初始时间
	 */
	var setStartTimeFun = function(datas){
		// 设置初始时间
		$('.datetimepicker').datetimepicker({
			language: 'cn',
			weekStart: 1,
			todayBtn: 1,
			autoclose: 1,
			Date: Date(),
			initialDate: new Date(),
			todayHighlight: 1,
			startView: 2,
			minView: 2,
			forceParse: 0
		});
		var firstDay = $("#firstDay").val();
		$("#firstDay").unbind("change");
		$("#firstDay").data("arg",{"datas":datas,"oldValue":firstDay});
		$("#firstDay").bind('change',onSetStartTime);
	}

	/**
	 * 单项修改、多项修改成功后的回调函数
	 */
	var ajaxChangeMedicineDoseCallBack = function(data,arg){
		$bb.toastShow("修改成功！");
		$servers.ajaxMedicineInfo(arg.datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 单项修改、多项修改
	 */
	var singleModify = function(key,obj,datas){
		if( obj.find("input").length == 0 ){
			var oldHtml = obj.html();
			var oldText = obj.attr("data-deValue");
			var width = obj.width();
			var h = '<input type="text" class="form-control" style="width:'+ width +'px">';
			obj.html(h).css({"width":width+11});
			if(key == "01") {
				obj.find("input").focus().val(oldText);
			}else{
				obj.find("input").val(oldText);
			}
		}else{
			var oldText = obj.find("input").val();
		}
		obj.find("input").unbind("blur");
		obj.find("input").blur(function(){
			obj.removeClass("active");
			var newText = $(this).val();
			if( newText == oldText ){
				obj.html(oldHtml);
			}else{
				var dealDate = obj.attr("data-dealDate");
				var params = {
					"oprInfo":{
						"channelId":channelId,
						"channelType":"2",
						"opType":"2",
						"opCode":"1231",
						"opNote":"【"+ doctorName +"】修改【"+ obj.attr("data-medicineName") +"】药物剂量",
					},
					"ptEhrEventInfos":[{
						"eventCode":$servers.getEventCodeByType(obj),
						"userId":datas.info.userId,
						"planId":obj.attr("data-planId"),
						"ptCourseId":datas.currCourse.ptCourseId,
						"ptEhrRecordInfos":[
							{
								"id":obj.attr("data-id"),
								"source":$servers.getSourceByDealDate(dealDate),
								"medicineId":obj.attr("data-medicineId"),
								"medicineDose":newText,
								"dealDate":dealDate,
								"note":"", // 药物交换时不能为空
							}
						]
					}]
				};
				$servers.ajaxChangeMedicineDose(params,ajaxChangeMedicineDoseCallBack,{"datas":datas});
			}
		});
	}

	/**
	 * 批量修改成功后的回调函数
	 */
	var batchModifyCallBack = function(data,arg){
		$("." + arg.className).modal("hide");
		$bb.toastShow("批量修改成功！");
		$servers.ajaxMedicineInfo(arg.datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 批量修改
	 */
	var batchModify = function($dom,datas){
		var className = "batchModifyModal";
		$bb.modal({
			"className": className,
			"size": "modal-sm",
            "tit": "请输入批量修改值",
		},function(){
	        $ui.batchModify({
	        	"dom":$("."+ className + " .modal-body")
	        });
	        $("." + className).modal('show');
	        $("#batchModifyInput").focus();
	        // 确认
	        $("." + className + " .batchModify-confirm").unbind("click");
	        $("." + className + " .batchModify-confirm").click(function(){
	        	var value = $("#batchModifyInput").val();
	        	if( value == "" ){
	        		$("#batchModifyInput").focus();
	        	}else{
	        		var ptEhrRecordInfos = [];
		        	$dom.each(function(i){
		        		var dealDate = $(this).attr("data-dealDate");
		        		var id = $(this).attr("data-id")
						var obj = {
							"source":$servers.getSourceByDealDate(dealDate),
							"medicineId":$(this).attr("data-medicineId"),
							"dealDate":dealDate,
							"medicineDose":value,
							//"note":"", // 药物交换时不能为空
						};
						if( id ) $.extend(obj,{"id":id});
						ptEhrRecordInfos.push(obj);
					});
					var params = {
						"oprInfo":{
							"channelId":channelId,
							"channelType":"2",
							"opType":"2",
							"opCode":"1231",
							"opNote":"【"+ doctorName +"】修改【"+ $dom.eq(0).attr("data-medicineName") +"】药物剂量",
						},
						"ptEhrEventInfos":[{
							"eventCode":$servers.getEventCodeByType($dom.eq(0)),
							"userId":datas.info.userId,
							"planId":$dom.eq(0).attr("data-planId"),
							"ptCourseId":datas.currCourse.ptCourseId,
							"ptEhrRecordInfos":ptEhrRecordInfos
						}]
					};
					var arg = {
						"datas":datas,
						"className":className
					}
					$servers.ajaxChangeMedicineDose(params,batchModifyCallBack,arg);
	        	}
	        });
	        // 取消
	        $("." + className + " .batchModify-cancel").unbind("click");
	        $("." + className + " .batchModify-cancel").click(function(){
	        	$("." + className).modal('hide');
	        });
        });
	}

	/**
	 * 查询溯源成功后的回调函数
	 */
	var ajaxGetTraceInfoCallBack = function(data,oDiv){
		var className = "recordModifyModal";
		$bb.modal({
			"className": className,
            "tit": "修改记录",
		},function(){
	        $ui.recordModify({ 
	        	"dom":$("." + className + " .modal-body"),
	        	"list":data
	        });
	        $("." + className).modal('show');
	        setTimeout(function(){
	        	if( $("body").hasClass("modal-open") ) oDiv.removeClass("active");
	        },1000);
        });
	}

	/**
	 * 药物溯源
	 */
	var recordModify = function(oDiv,datas){
		var params = {
			"oprInfo":{
				"channelId":channelId,
				"channelType":"2",
			},
			"busiId":datas.currCourse.ptCourseId,
			"userId":datas.info.userId,
			"dealDate":oDiv.attr("data-dealDate"),
			"deList":[{
				"refDeValueList":[oDiv.attr("data-medicineId")]
			}],
		};
		$servers.ajaxGetTraceInfo(params,ajaxGetTraceInfoCallBack,oDiv);
	}

	/**
	 * 交换
	 */
	var exchange = function(obj){
		//obj.parent("td").addClass("exchange");
	}

	/**
	 * 用药记录成功后的回调函数
	 */
	var medicationRecordCallBack = function(data,arg){
		$("." + arg.className).modal("hide");
		$bb.toastShow("用药记录成功！");
		$servers.ajaxMedicineInfo(arg.datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 用药记录
	 */
	var onIsDrugUse = function(){
		var arg = $(this).data("arg");
		var value = $("." + arg.className + " .medicationRecord-modal input").val();
    	if( value == "" ){
    		$("." + arg.className + " .medicationRecord-modal input").focus();
    	}else{
    		var dealDate = arg.oDiv.attr("data-dealDate");
			var params = {
				"oprInfo":{
					"channelId":channelId,
					"channelType":"2",
					"opType":"2",
					"opCode":"1231",
					"opNote":"【"+ doctorName +"】修改【"+ arg.oDiv.attr("data-medicineName") +"】药物剂量",
				},
				"ptEhrEventInfos":[{
					"eventCode":$servers.getEventCodeByType(arg.oDiv),
					"userId":arg.datas.info.userId,
					"planId":arg.oDiv.attr("data-planId"),
					"ptCourseId":arg.datas.currCourse.ptCourseId,
					"ptEhrRecordInfos":[{
						"id":arg.oDiv.attr("data-id"),
						"source":$servers.getSourceByDealDate(dealDate),
						"medicineId":arg.oDiv.attr("data-medicineId"),
						"dealDate":dealDate,
						"medicineDose":value,
						"dealStatus":arg.dealStatus, // 当天用药完成传02，未完成不传
					}],
				}]
			};
			$servers.ajaxChangeMedicineDose(params,medicationRecordCallBack,arg);
    	}
	}

	/**
	 * 用药记录
	 */
	var medicationRecord = function(oDiv,datas){
		var value = oDiv.attr("data-deValue");
		var medicineName = oDiv.attr("data-medicineName");
		var medUnitName = oDiv.attr("data-medUnitName");
		var className = "medicationRecordModal";
		$bb.modal({
			"className":className,
			"tit":"用药记录",
			"size":"modal-sm"
		},function(){
			$ui.medicationRecord({
				"dom":$("." + className + " .modal-body"),
				"data":{
					"value":value,
					"medicineName":medicineName,
					"medUnitName":medUnitName,
				}
			});
			$("." + className).modal("show");
			$("." + className + " .drugNotUse").unbind('click');
			$("." + className + " .drugNotUse").data("arg",{"oDiv":oDiv,"datas":datas,"className":className});
			$("." + className + " .drugNotUse").click(onIsDrugUse);
			$("." + className + " .drugUsed").unbind('click');
			$("." + className + " .drugUsed").data("arg",{"oDiv":oDiv,"datas":datas,"className":className,"dealStatus":"02"});
			$("." + className + " .drugUsed").click(onIsDrugUse);
		});
	}

	/**
	 * 对右击面板进行的一系列操作(单项修改、多项修改、批量修改、交换、修改记录/药物溯源)
	 */
	var onOperation = function(){
		var key = $(this).attr("data-key");
		var datas = $(this).data("datas");
		switch( key ){
			case "01": // 单项修改
				var oDiv = $(this).data("oDiv");
				singleModify(key,oDiv,datas);
				break;
			case "02": // 多项修改
				var $dom = $(this).data("dom");
				$dom.each(function(i){
					singleModify(key,$dom.eq(i),datas);
				});
				break;
			case "03": // 批量修改
				var $dom = $(this).data("dom");
				batchModify($dom,datas);
				break;
			case "04": // 交换 暂时未做
				var oDiv = $(this).data("oDiv");
				exchange(oDiv);
				break;
			case "05": // 药物溯源
				var oDiv = $(this).data("oDiv");
				recordModify(oDiv,datas);
				break;
			case "06": // 用药记录
				var oDiv = $(this).data("oDiv");
				medicationRecord(oDiv,datas);
				break;
		}
	}

	/**
	 * 药品操作
	 */
	var medicineFun = function(datas){
		var $doms = $(".medicine").not(".disabled");
		$event.bannedDefaultRightClick( $doms,$doms.not(".active") );
		$doms.unbind("click");
		$doms.click(function(){
			var $domActive = $(".medicine.active");
			$(".specialtyBag-date").removeClass("active").removeAttr("data-toggle");
			// 选中
			if( $(this).hasClass("active") ){
				$(this).removeClass("active").removeAttr("data-toggle");
			}else{
				$(this).addClass("active").attr("data-toggle","context");
				// 选择不同药品时，前面选中的药品取消
				var medicineId = $(this).attr("data-medicineId");
				if( $domActive.length > 0 ){
					$domActive.each(function(i){
						if( $(this).attr("data-medicineId") != medicineId ){
							$(this).removeClass("active").removeAttr("data-toggle");
						}
					});
				}
			}
			$domActive = $(".medicine.active");
			// 没选中的禁掉右击
			$event.bannedDefaultRightClick( $doms,$doms.not(".active") );
			// 重新绑定
			$doms.off("contextmenu.context.data-api");
			$domActive.contextmenu({
	        	target:'#contextmenu',
				before: function(e,context) {
					var oDiv = $(e.currentTarget); // 一个
					var $dom = $(e.currentTarget).parent().parent().find("td.medicine.active"); // 多个
					var list =  $servers.getDrugOperateData(oDiv,$dom);
					var beginDate, date = oDiv.attr("data-dealDate");
					for (var i = 0; i < datas.supplyMedicine.length; i++) {
						if( datas.supplyMedicine[i].medicineId == oDiv.attr("data-medicineId") ){
							beginDate = datas.supplyMedicine[i].beginDate;
						}
					}
					if( $bb.simple.dateDiff(beginDate,date).days >= 0 ){
						$ui.contextmenu({
							"list":$servers.getDrugOperate(list)
						});
						$("#contextmenu ul.dropdown-menu li").unbind("click");
						$("#contextmenu ul.dropdown-menu li").data({"oDiv":oDiv,"dom":$dom,"datas":datas});
						$("#contextmenu ul.dropdown-menu li").click(onOperation);
					}else{
						$("#contextmenu").html("");
					}
				},
				onItem: function(context,e){}
	        });
		});
	}

	/**
	 * 请求终止方案成功后的回调函数
	 */
	var ajaxStopSchemeCallBack = function(data,arg){
		$bb.toastShow("方案终止成功！");
		$("." + arg.className).modal("hide");
		specialtyBags.init(arg.datas);
	}

	/**
	 * 请求终止方案
	 */
	var onSureStopScheme = function(){
		var arg = $(this).data("arg");
		var expireReason = $("." + arg.className + " input[name=expireReason]").val();
		if( expireReason == "" ){
			$("." + arg.className + " input[name=expireReason]").focus();
		}else{
			var params = {
				"oprInfo":{
					"channelId":channelId,
					"channelType":"2",
					"opType":"2",
					"opCode":"1239",
					"opNote":"终止方案",
				},
				"ptDisCourseInfo":{
					"expireDate":arg.$td.text(),
					"expireReason":expireReason,
					"planId":arg.datas.currScheme.planId,
					"id":arg.datas.currCourse.ptCourseId,
				}
			};
			$servers.ajaxStopScheme(params,ajaxStopSchemeCallBack,arg);
		}
	}

	/**
	 * 填写终止方案的原因
	 */
	var onStopScheme = function(){
		var arg = $(this).data("arg");
		var expireDate = arg.$td.text();
		var nowDate = $bb.simple.getCurTime().date;
		if( $bb.simple.dateDiff(expireDate,nowDate).days >= 0 ){
			$bb.toastShow("终止日期必须大于今天！");
		}else{
			var className = "stopSchemeReasonModal";
			arg.className = className;
			$bb.modal({
				"className":className,
				"tit":"请填写终止方案的原因",
				"size":"modal-sm"
			},function(){
				$ui.stopSchemeReason({
					"dom":$("." + className + " .modal-body"),
				});
				// 确定
				$("." + className).modal("show");
				$("." + className + " .sure").unbind("click");
				$("." + className + " .sure").data("arg",arg);
				$("." + className + " .sure").click(onSureStopScheme);
				// 取消
				$("." + className + " .cancel").unbind("click");
				$("." + className + " .cancel").click(function(){
					$("." + className).modal("hide");
				});
			});
		}
	}

	/**
	 * 终止方案
	 */
	var stopScheme = function(datas,domId){
		var $doms = $("#"+ domId +" .specialtyBag-date").not(".disabled");
		$event.bannedDefaultRightClick( $doms );
		$doms.unbind("click");
		$doms.click(function(){
			$("td").removeClass("active").removeAttr("data-toggle");
			$(this).addClass("active").attr("data-toggle","context");
			// 没选中的禁掉右击
			$event.bannedDefaultRightClick( $doms,$doms.not(".active") );
			// 重新绑定
			$doms.off("contextmenu.context.data-api");
			$(this).contextmenu({
	        	target:'#contextmenu',
				before: function(e,context) {
					var $td = $(e.currentTarget);
					$ui.contextmenu({
						"list":[{
							"key":"stopScheme",
			                "text":"终止本方案"
						}]
					});
					$("#contextmenu ul.dropdown-menu li").unbind("click");
					$("#contextmenu ul.dropdown-menu li").data("arg",{"$td":$td,"datas":datas});
					$("#contextmenu ul.dropdown-menu li").click(onStopScheme);
				},
				onItem: function(context,e){}
	        });
		});
	}

	/**
	 * 补充用药应用成功后的回调函数
	 */
	var ajaxApplyMedicineCallBack = function(data,arg){
		$("." + arg.className).modal("hide");
		$bb.toastShow("补充药品添加成功！");
		$servers.ajaxMedicineInfo(arg.datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 引用补充药品
	 */
	var onApplyMedicine = function(){
		var arg = $(this).data("arg");
		var medSkuId = $(this).parents("li").attr("data-medSkuId");
		var params = {
			"oprInfo":{
				"channelId":channelId,
				"channelType":"2",
				"opType":"2",
				"opCode":"1233",
				"opNote":"添加补充用药",
			},
			"userId":arg.datas.info.userId,
			"ptCourseId":arg.datas.currCourse.ptCourseId,
			"medSkuId":medSkuId,
		}
		$servers.ajaxApplyMedicine(params,ajaxApplyMedicineCallBack,arg);
	};

	/**
     * 请求修改药品接口成功后的回调函数
     */
    var ajaxUpdateCallBack = function(data,arg) {
        $('.' + arg.className2).modal('hide');
        $servers.ajaxGetMedSkus(ajaxGetMedSkusCallBack,arg.datas);
    }

    /**
     * 修改药品
     */
    var onUpdate = function() {
        var arg = $(this).data("arg");
        var medicineName = $.trim($("#medicineName").val());
        var classId = $("#classId").val();
        var catalogId = $("#catalogId").val();
        var frequencyDay = parseInt($("#frequencyDay").val());
        var frequencyTime = parseInt($("#frequencyTime").val());
        var calcuMethod = $("#calcuMethod").val();
        var medicineDose = parseFloat($("#medicineDose").val());
        var medUnitId = $("#medUnitId").val();
        var medicineType = $("#medicineType").val();
        var character = $("#character").val();
        var indication = $("#indication").val();
        var adverseReaction = $("#adverseReaction").val();
        var taboo = $("#taboo").val();
        var considerations = $("#considerations").val();
        var id = $(this).attr("data-id");
        var medicineId = $(this).attr("data-medicineId");
        var params = {
            "oprInfo":{
                "opCode": "2036",
                "opType": "3",
                "opNote": "【" + doctorName + "】修改药品【" + medicineName + "】",
                "channelType": "2",
                "channelId": channelId
            },
            "medicineInfo":{
                "medicineName": medicineName,
                "classId": classId,
                "catalogId": catalogId,
                "id": medicineId,
            },
            "medSkuInfo":{
                "medicineDose": medicineDose,
                "calcuMethod": calcuMethod,
                "frequencyDay": frequencyDay,
                "frequencyTime": frequencyTime,
                "useUnitId": medUnitId, // 服用剂量单位 使用药物剂量单位
                "medUnitId": medUnitId,
                "medicineType": medicineType,
                "character": character,
                "indication": indication,
                "adverseReaction": adverseReaction,
                "taboo": taboo,
                "considerations": considerations,
                "id":id,
            }
        };
        if ( !medicineName || medicineName == '' ) {
            $bb.toastShow('药品名称不能为空');
            return;
        }
        if ( !frequencyDay || frequencyDay == '' ) {
            $bb.toastShow('服用周期天数不能为空');
            return;
        }
        if ( !frequencyTime || frequencyTime == '' ) {
            $bb.toastShow('服用周期次数不能为空');
            return;
        }
        if ( !medicineDose || medicineDose == '' ) {
            $bb.toastShow('药品剂量不能为空');
            return;
        }
        $servers.ajaxUpdate(params,ajaxUpdateCallBack,arg);
    }

    /**
     * 模态框小类回调函数
     */
    var modalSmallClass = function(data) {
        $ui.smallClass({
            "id": "catalogId",
            "smallClass": data.medCatalogInfos,
        });
    }

    /**
     * 模态框里的大类改变时触发
     */
    var onChangeBigClass = function(){
        var bigClassId = $(this).val();
        var params = {
            "medCatalogInfo":{ 
                "classId": bigClassId
            }
        };
        $servers.ajaxMedicineSmallClass(params,modalSmallClass);
    }

    /**
     * 添加成功后的回调函数
     */
    var ajaxAddCallBack = function(data,arg) {
        $('.' + arg.className2).modal('hide');
        $bb.toastShow("添加药品成功！");
        $servers.ajaxGetMedSkus(ajaxGetMedSkusCallBack,arg.datas);
    }

    /**
     * 添加药品
     */
    var onAdd = function() {
        var medicineName = $.trim($("#medicineName").val());
        var classId = $("#classId").val();
        var catalogId = $("#catalogId").val();
        var frequencyDay = parseInt($("#frequencyDay").val());
        var frequencyTime = parseInt($("#frequencyTime").val());
        var calcuMethod = $("#calcuMethod").val();
        var medicineDose = parseFloat($("#medicineDose").val());
        var medUnitId = $("#medUnitId").val();
        var medicineType = $("#medicineType").val();
        var character = $("#character").val();
        var indication = $("#indication").val();
        var adverseReaction = $("#adverseReaction").val();
        var taboo = $("#taboo").val();
        var considerations = $("#considerations").val();
        var params = {
            "oprInfo":{
                "opCode": "2045",
                "opType": "3",
                "opNote": "【" + doctorName + "】添加药品【" + medicineName + "】",
                "channelType": "2",
                "channelId": channelId
            },
            "medicineInfo":{
                "medicineName": medicineName,
                "classId": classId,
                "catalogId": catalogId
            },
            "medSkuInfo":{
                "medicineDose": parseFloat(medicineDose),
                "calcuMethod": calcuMethod,
                "frequencyDay": parseInt(frequencyDay),
                "frequencyTime": parseInt(frequencyTime),
                "useUnitId": medUnitId, // 服用剂量单位 使用药物剂量单位
                "medUnitId": medUnitId,
                "medicineType": medicineType,
                "character": character,
                "indication": indication,
                "adverseReaction": adverseReaction,
                "taboo": taboo,
                "considerations": considerations
            }
        };
        if ( !medicineName || medicineName == '' ) {
            $bb.toastShow('药品名称不能为空');
            return;
        }
        if ( !frequencyDay || frequencyDay == '' ) {
            $bb.toastShow('服用周期天数不能为空');
            return;
        }
        if ( !frequencyTime || frequencyTime == '' ) {
            $bb.toastShow('服用周期次数不能为空');
            return;
        }
        if ( !medicineDose || medicineDose == '' ) {
            $bb.toastShow('药品剂量不能为空');
            return;
        }
        var arg = $(this).data("arg");
        $servers.ajaxAdd(params,ajaxAddCallBack,arg);
    }

    /**
     * 选择搜索出的某一个药品
     */
    var selectMedicineName = function() {
        var datas = $(this).data("datas");
        $("#inputQuery").hide();
        var index = $(this).index();
        datas.arg.status = "update";
        //datas.medicines[index].resetFlag = true;
        datas.arg.medSkuInfo = datas.medicines[index];
        modalUi(datas.arg);
    }

    /**
     * 根据药品名称查询药品成功后的回调函数
     */
    var ajaxSelectCallBack = function(data,arg) {
        if( data.rows.length > 0 ){
            $ui.selectCallBack({
                "id": "inputQuery",
                "list": data.rows
            });
            $("#inputQuery").show();
            $("#inputQuery .query_item").unbind("click");
            $("#inputQuery .query_item").data("datas",{"arg":arg,"medicines":data.rows});
            $("#inputQuery .query_item").click(selectMedicineName);
        }else{
            $("#inputQuery").hide();
        }
    }

    /**
     * 模态框内的药名搜索
     */
    var onSelectByName = function() {
        var arg = $(this).data("arg");
        var medicineName = $("#medicineName").val();
        var params = { 
        	"medicineName": medicineName,
        	"medicineType": "2"
        };
        $servers.ajaxSelect(params,ajaxSelectCallBack,arg);
    }

    /**
     * 重置
     */
    var onReset = function(){
        var arg = $(this).data("arg");
        arg.status = "add";
        modalUi(arg);
    }

	/**
     * 模态框初始化
     */
    var modalUi = function(arg,obj){
        var options = {
            "dom": $("." + arg.className2 + " .modal-body"),
            "status":arg.status,
            "units":arg.units,
            "bigClass":arg.bigClass,
            "smallClass":arg.smallClass,
        };
        if( arg.status == "update" ) $.extend(options,arg.medSkuInfo);
        $ui.add(options);
        $("." + arg.className2).modal("show");
        // 模态框内的药名搜索
        $("#medicineName").unbind("input propertychange");
        $("#medicineName").data("arg",arg);
        $("#medicineName").bind("input propertychange", onSelectByName);
        // 重置
        $("#reset").unbind("click");
        $("#reset").data("arg",arg);
        $("#reset").bind("click", onReset);
        if( arg.status == "update" ){
        	// 修改药品
	        $("#add").unbind("click");
	        $("#add").data("arg",arg);
	        $("#add").click(onUpdate);
        }else{
        	// 大类改变时触发
	        $("#classId").unbind("change");
	        $("#classId").change(onChangeBigClass);
            // 添加药品并应用给疗程
            $("#add").unbind("click");
            $("#add").data("arg",arg);
            $("#add").bind("click",onAdd);
        }
    }

    /**
     * 请求大类成功后的回调函数
     */
    var ajaxSmallClassCallBack = function(data,arg){
        arg.smallClass = data.medCatalogInfos;
        arg.className2 = "medicineEditModal";
        var tit = arg.status == "update" ? "补充药品修改页" : "补充药品添加页";
        $bb.modal({
            "className": arg.className2,
            "tit": tit,
        }, function() {
            modalUi(arg);
        });
    }

    /**
     * 模态框大类回调函数
     */
    var ajaxBigClass = function(data,arg) {
        arg.bigClass = data.data;
        var classId = arg.medSkuInfo && arg.medSkuInfo.class_id ? arg.medSkuInfo.class_id : data.data[0].id;
        var params = {
            "medCatalogInfo":{
                "classId":classId
            }
        };
        $servers.ajaxMedicineSmallClass(params,ajaxSmallClassCallBack,arg);
    }

    /**
     * 查询药品单位回调函数
     */
    var ajaxQueryUnit = function(data,arg) {
        arg.units = data.medUnits;
        $servers.ajaxMedicineBigClass(ajaxBigClass,arg);
    }

    /**
     * 获取药品信息成功后的回调函数
     */
    var medDetailCallback = function(data,arg){
    	arg.medSkuInfo = data.medSkuInfo;
        $servers.ajaxQueryUnit(ajaxQueryUnit,arg);
    }

    /**
     * 点击修改事件
     */
    var onEditMedicine = function() {
    	var arg = $(this).data("arg");
    	if( arg.status == "update" ){
	    	var medSkuId = $(this).parents("li").attr("data-medSkuId");
	    	var params = {
	            "medSkuInfo":{
	                "id": medSkuId
	            }
	        };
	        $servers.ajaxGetMedInfo(params,medDetailCallback,arg);
        }else if( arg.status == "add" ){
        	$servers.ajaxQueryUnit(ajaxQueryUnit,arg);
        }
    }

    /**
     * 药品列表
     */
    var medicineList = function(datas,list,className){
    	$ui.medicineList({
			"dom":$("." + className + " .modal-body"),
			"list":list
		});
		$("." + className).modal("show");
		// // 添加药品
		$("#addMedicine").unbind("click");
		$("#addMedicine").data("arg",{"datas":datas,"className":className,"status":"add"});
		$("#addMedicine").click(onEditMedicine);
		// 修改药品
		$("."  + className + " .edit").unbind("click");
		$("."  + className + " .edit").data("arg",{"datas":datas,"className":className,"status":"update"});
		$("."  + className + " .edit").click(onEditMedicine);
		// 应用药品
		$("."  + className + " .apply").unbind("click");
		$("."  + className + " .apply").data("arg",{"datas":datas,"className":className});
		$("."  + className + " .apply").click(onApplyMedicine);
    }

	/**
	 * 获取用药列表成功后的回调函数
	 */
	var ajaxGetMedSkusCallBack = function(data,datas){
		if( data.rows && $.inArray(data.rows) ){
			var className = "medicineListModal";
			if( $("." + className).length > 0 ){
				medicineList(datas,data.rows,className);
			}else{
				$bb.modal({
					"id":"specialtyBags-modalBox",
					"className":className,
					"tit":"补充用药药品库"
				},function(){
					var h = '<div id="addMedicine" class="medicineList-modal-add"><i class="fa fa-plus"></i></div>';
					$("." + className + " .modal-title").append(h);
					medicineList(datas,data.rows,className);
				});
			}
		}
	}

	/**
	 * 补充用药
	 */
	var onMedicineDatabaseClick = function(){
		var datas = $(this).data("datas");
		$servers.ajaxGetMedSkus(ajaxGetMedSkusCallBack,datas);
	}

	/**
	 * 停止用药成功后的回调函数
	 */
	var ajaxStopMedicineCallBack = function(data,arg){
		$bb.toastShow("已终止");
		$servers.ajaxMedicineInfo(arg.datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 停止用药
	 */
	var stopMedicine = function(arg){
		var params = {
			"oprInfo":{
				"channelId":channelId,
				"channelType":"2",
				"opType":"2",
				"opCode":"1234",
				"opNote":"【"+ doctorName +"】停止用"+ arg.dom.text() +"补充药",
			},
			"busiId":arg.datas.currCourse.ptCourseId,
			"ptStageId":arg.datas.currStage.ptStageId,
			"medicineId":arg.dom.attr("data-medicineId"),
			"userId":arg.datas.info.userId,
		};
		$servers.ajaxStopMedicine(params,ajaxStopMedicineCallBack,arg);
	}

	/**
	 * 保存备注信息成功后的回调函数
	 */
	var ajaxInsertRemarkCallBack = function(data,params){
		$("." + params.className).modal("hide");
		$bb.toastShow("备注修改成功！");
		specialtyBags.init(params.datas);
	}

	/**
	 * 保存
	 */
	var onSave = function(){
		var params = $(this).data("params");
		var values = $form.getSaveData("remarkContent");
		var arg = {
			"oprInfo":{
				"opCode":"1241",
				"opType":"2",
				"opNote":"【"+ doctorName +"】给【"+ params.datas.info.userName +"】患者修改备注信息" ,
				"channelType":"2",
				"channelId":channelId
			},
			"eventList":[
				{
					"busiId":params.datas.currCourse.ptCourseId,
					"eventCode":params.eventCode,
					"dealDate":params.dealDate,
					"planId":params.datas.currScheme.planId,
					"deList":$servers.getSaveValue(values,params),
				}
			],
			"remarkValue":params.remarkValue,
		}
		$servers.ajaxInsertRemark(arg,ajaxInsertRemarkCallBack,params);
	}

	/**
	 * 警示信息查询成功后的回调函数
	 */
	var ajaxPtWarnMsgCallBack2 = function(data,params){
		if( data ){
			for(var key in data){
				var obj = {"deCode":key,"quesValue":data[key]}
				params.values.push(obj);
			}
		}
		$form.init({
			"id":"remarkContent",
			"questions":params.questions,
			"values":params.values,
		});
		// 取消
		$("." + params.className + " .cancel").unbind("click");
		$("." + params.className + " .cancel").data("params",params);
		$("." + params.className + " .cancel").click($event.onCancel);
		// 保存
		$("." + params.className + " .save").unbind("click");
		$("." + params.className + " .save").data("params",params);
		$("." + params.className + " .save").click(onSave);
	}

	/**
	 * 随访备注内容查询成功后的回调函数
	 */
	var ajaxRemarkContentCallBack = function(data,params){
		var values = $servers.getValue(data.rows);
		params.values = values;
		if( params.eventCode == "C0002.0302.01" ){
			var arg = {
				"userId":params.datas.info.userId,
				"flag":"2"
			};
			$servers.ajaxPtWarnMsg(arg,ajaxPtWarnMsgCallBack2,params);
		}else{
			ajaxPtWarnMsgCallBack2(null,params);
		}
	}

	/**
	 * 查询专科袋备注模板成功后的回调函数
	 */
	var ajaxReamrkJsonStrCallBack = function(data,params){
		if( data && data.templ_data ){
			var templData = JSON.parse( data.templ_data );
			var questions = [{"templData":templData}];
			params.questions = questions;
			var arg = {
				"oprInfo":{
					"channelType":"2",
					"channelId":channelId
				},
				"busiId":params.datas.currCourse.ptCourseId,
				"userId":params.datas.info.userId,
				"dealDate":params.dealDate,
				"deList":[{
					"refDeValueList":[params.code]
				}],
			}
			$servers.ajaxRemarkContent(arg,ajaxRemarkContentCallBack,params);
		}
	}

	/**
	 * 选择tab
	 */
	var onTabSelect = function(){
		$(this).addClass("active").siblings().removeClass("active");
		var params = $(this).data("params");
		params.code = $(this).attr("data-code");
		params.eventCode = $(this).attr("data-eventCode");
		$servers.ajaxReamrkJsonStr(params,ajaxReamrkJsonStrCallBack);
	}

	/**
	 * 备注
	 */
	var onRemark = function(){
		var datas = $(this).data("datas");
		var dealDate = $(this).attr("data-dealDate");
		if( $bb.simple.dateDiff($bb.simple.getCurTime().date,dealDate).days > 0 ){
			$bb.toastShow("不能选择未来日期！");
		}else{
			var remarkValue = $(this).children().html();
			var className ="remarkModal";
			$bb.modal({
				"className":className,
				"tit":"备注",
				"size":"modal-lg"
			},function(){
				$ui.remark({
					"dom":$("." + className + " .modal-body"),
				});
				$("." + className).modal("show");
				$("." + className + " .remark-tabs > span").unbind("click");
				$("." + className + " .remark-tabs > span").data("params",{"className":className,"datas":datas,"dealDate":dealDate,"remarkValue":remarkValue});
				$("." + className + " .remark-tabs > span").click(onTabSelect);
				$("." + className + " .remark-tabs > span").eq(0).click();
			});
		}
	}

	/**
	 * 添加一行成功后的回调函数
	 */
	var ajaxAddDayCallBack = function(data,datas){
		$bb.toastShow("添加一行成功！");
		// 专科袋药品表头信息查询
		$servers.ajaxMedicineInfo(datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 添加一行
	 */
	var onAddDay = function(){
		var key = $(this).attr("data-key");
		if( key == "01" ){
			var datas = $(this).data("datas");
			var dealDate = datas.days[datas.days.length - 1].dealDate;
			var params = {
				"oprInfo":{
					"channelId":channelId,
					"channelType":"2",
					"opType":"2",
					"opCode":"1237",
					"opNote":"【"+ doctorName +"】给【"+ datas.info.userName +"】专科袋添加一行",
				},
				"ptEhrEventInfos":[
					{
						"dealDate":dealDate,
						"eventCode":"C0002.0201.02",
						"ptCourseId":datas.currCourse.ptCourseId,
						"userId":datas.info.userId,
						"planId":datas.currScheme.planId,
					}
				]
			};
			$servers.ajaxAddDay(params,ajaxAddDayCallBack,datas);
		}
	}

	/**
	 * 肝肾检查
	 */
	var onLiverKidneyCheck = function(){
		var obj = $(this);
		if( obj.find("input").length == 0 ){
			var oldHtml = obj.html();
			var oldText = obj.find("font").html();		
			var width = obj.width();
			var h = '<input type="text" class="form-control" style="width:'+ width +'px">';
			obj.html(h).css({"width":width+11});
			obj.find("input").focus().val(oldText);
		}else{
			var oldText = obj.find("input").val();
			var oldHtml = "<font>"+ oldText +"</font>";
		}
		obj.find("input").unbind("blur");
		obj.find("input").blur(function(){
			obj.removeClass("active");
			var newText = $(this).val();
			if( newText == oldText ){
				obj.html(oldHtml);
			}else{
				// 没有接口，暂时放着
			}
		});
	}

	/**
	 * 专科袋疗程药品剂量查询成功后的回调函数
	 */
	var ajaxListPtCourseMedDoseCallBack = function(data,datas){
		$ui.statistics({
			"id":"specialtyBagsLegend",
			"data":data.statistics
		});
		// table 初始化
		var domId = "dataDetailsTable"; // 包裹表格的dom元素的id
		$ui.table({
			"id":domId,
			"courseMedicine":datas.courseMedicine,
			"supplyMedicine":datas.supplyMedicine,
			"days":data.rows,
			"expireDate":datas.currScheme.expireDate
		});
		// 终止的方案不可以点击
		if( datas.currScheme.expireDate ) return;
		// 设置初始时间
		setStartTimeFun(datas);
		// 是否设置了初始日期
		var isSetInitDate = data.rows.length > 0 && data.rows[0].dealDate ? true : false;
		// 没有设置初始日期时，点击tbody里的td的响应
		if( !isSetInitDate ){
			var $dom = $("#"+ domId +" td.add-row,#"+ domId +" td.specialtyBag-date,#"+ domId +" td.medicine,#"+ domId +" td.remark");
			$dom.unbind("click");
			$dom.click(function(){
				$bb.toastShow("请先设置初始日期！");
			});
		}else{
			// 终止方案
			stopScheme(datas,domId);
			// 药品
			medicineFun(datas);
			// 备注
	        var $domRemark = $("#"+ domId +" .remark");
	        $domRemark.unbind("click");
	        $domRemark.data("datas",datas);
	        $domRemark.click(onRemark);
	        // 添加一行 暂时不做
	        $("#"+ domId +" .add-row").off("contextmenu.context.data-api");
	        $("#"+ domId +" .add-row").contextmenu({
	        	target:'#contextmenu',
				before: function(e,context) {
					var oDiv = $(e.currentTarget);
					$ui.contextmenu({
						"list":[
							{
				                "key":"01",
				                "text":"添加一行",
				            },
				            {
				                "key":"02",
				                "text":"取消",
				            }
						]
					});
					datas.days = data.rows;
					$("#contextmenu ul.dropdown-menu li").unbind("click");
					$("#contextmenu ul.dropdown-menu li").data("datas",datas);
					$("#contextmenu ul.dropdown-menu li").click(onAddDay);
				},
				onItem: function(context,e){}
	        });
	        // 肝肾检查（没有接口暂时不做）
	        /*$("#"+ domId +" .liver-kidney-check").unbind("click");
	        $("#"+ domId +" .liver-kidney-check").click(onLiverKidneyCheck);*/
		}
		// 药品库 补充用药
		$("#medicineDatabaseBtn").unbind("click");
		$("#medicineDatabaseBtn").data("datas",datas);
		$("#medicineDatabaseBtn").click(onMedicineDatabaseClick);
		// 终止用药
		var $domSupplyMedicineHead = $("#" + domId + " .supplyMedicine-head");
		$event.bannedDefaultRightClick( $domSupplyMedicineHead );
		$domSupplyMedicineHead.off("contextmenu.context.data-api");
		$domSupplyMedicineHead.contextmenu({
			target:'#contextmenu',
			before: function(e,context) {
				$("#contextmenu").html("");
				var oDiv = $(e.currentTarget);
				$bb.toastConfirmShow(stopMedicine,{"datas":datas,"dom":oDiv},"您确认要停用"+ datas.info.userName +"的"+ oDiv.text() +"补充用药计划吗？停止后将不再生成该补充用药计划。");
			},
			onItem: function(context,e){}
        });
        // 打印
        $("#printBtn").unbind("click");
        $("#printBtn").click($event.onPrint);
	}

	/**
	 * 专科袋药品表头信息查询成功后的回调函数
	 */
	var ajaxMedicineInfoCallBack = function(data,datas){
		datas.courseMedicine = data.courseMedicine.rows;
		datas.supplyMedicine = data.supplyMedicine.rows;
		// 专科袋疗程药品剂量查询
		var decodeDrugDoses = $bb.code.getDeCodeByName("drugDoses");
		var importantLevel = $bb.code.getDeCodeByName("importantLevel");
		var remark = $bb.code.getDeCodeByName("remark");
		var params = {
			"oprInfo":{
				"channelType":"2",
				"channelId":channelId,
			},
			"busiId":datas.currCourse.ptCourseId,
			"userId":datas.currScheme.userId,
			"deList":[
				{
					"deCode":decodeDrugDoses
				},
				{
			        "deCode":remark // 备注信息
			    },
			    {
			      	"deCode":importantLevel, // 重要级别
			      	"refDeValueList":["D0001"]
			    },
			    { "deCode":$bb.code.getDeCodeByName("WBC") },
			    { "deCode":$bb.code.getDeCodeByName("ANC") },
			    { "deCode":$bb.code.getDeCodeByName("Hb") },
			    { "deCode":$bb.code.getDeCodeByName("Plt") },
			    { "deCode":$bb.code.getDeCodeByName("temperature") },
			    { "deCode":$bb.code.getDeCodeByName("liverAndKidneyCheck") }
			]
		};
		$servers.ajaxListPtCourseMedDose(params,ajaxListPtCourseMedDoseCallBack,datas);
	}

	/**
	 * 选择疗程
	 */
	var onCourseSelect = function(){
		var datas = $(this).data("datas");
		var index = $(this).index();
		var ptStageId = $(this).attr("ptStageId");
		datas.currStage = $servers.getCurrStage(datas.currScheme.ptDisStagePOs,ptStageId);
		datas.currCourse = datas.currStage.ptDisCoursePOs[index];
		datas.currCourseIndex = index;
		$("#" + datas.domId + " .stages-list li[ptStageId="+ ptStageId +"]").addClass("active").siblings().removeClass("active");
		$("#" + datas.domId + " .course-list li li").removeClass("active");
		$(this).addClass("active");
		// 初始化title、info
		initUi(datas);
		// 专科袋药品表头信息查询
		$servers.ajaxMedicineInfo(datas,ajaxMedicineInfoCallBack);
	}

	/**
	 * 选择阶段
	 */
	var onStageSelect = function(){
		var datas = $(this).data("datas");
		var index = $(this).index();
		if( datas.currScheme.ptDisStagePOs[index].ptDisCoursePOs.length > 0 ){
			datas.currStage = datas.currScheme.ptDisStagePOs[index];
			datas.currStageIndex = index;
			$(this).addClass("active").siblings().removeClass("active");
			var $courses = $("#" + datas.domId + " .course-list li.course-list-group");
			$courses.find("li").unbind("click");
			$courses.find("li").data("datas",datas);
			$courses.find("li").click(onCourseSelect);
			$courses.eq(index).find("li").eq(datas.currCourseIndex).click();
		}else{
			$bb.toastShow("该阶段下没有疗程！");
		}
	}

	/**
	 * 选择方案
	 */
	var onSchemeSelect = function(){
		$(this).addClass("active").siblings().removeClass("active");
		var datas = $(this).data("datas");
		var index = $(this).index();
		datas.currScheme = datas.schemes[index];
		if( datas.currScheme.ptDisStagePOs.length > 0 ){
			var currIndex = $servers.getCurrStageIndex(datas.currScheme.ptDisStagePOs);
			if( !datas.currStageIndex ) datas.currStageIndex = currIndex.currStageIndex;
			if( !datas.currCourseIndex ) datas.currCourseIndex = currIndex.currCourseIndex;
			datas.domId = "specialtyBagsStagesCourse";
			$ui.sidebar({
				"id":datas.domId,
				"list":datas.currScheme.ptDisStagePOs
			});
			// 选择阶段
			var $stages = $("#" + datas.domId + " .stages-list li");
			$stages.unbind("click");
			$stages.data("datas",datas);
			$stages.click(onStageSelect);
			$stages.eq(datas.currStageIndex).click();
			$event.stagesCourseBoxToggle(datas.domId); // 悬浮菜单的显示或隐藏
		}
	}

	/**
	 * 查询实例化的方案成功后的回调函数
	 */
	var ajaxPtDisPlanInfoCallBack = function(data,datas){
		datas.schemes = data;
		if( data.length > 0 ){
			var domId = "specialtyBagsScheme";
			$ui.scheme({
				"id":domId,
				"list":data
			});
			var display = data.length <= 1 ? "none" : "block";
			$("#" + domId).css({"display":display});
			$("#" + domId + " .item").unbind("click");
			$("#" + domId + " .item").data("datas",datas);
			$("#" + domId + " .item").click(onSchemeSelect);
			var currSchemeIndex = $servers.getSchemeIndex(data,datas.currScheme);
			$("#" + domId + " .item").eq(currSchemeIndex).click();
		}
	}

	specialtyBags.init = function(datas){
		if( !datas ){
			var datas = {};
			datas.info = $bb.getPageParams();
		}
		$servers.ajaxPtDisPlanInfo(datas,ajaxPtDisPlanInfoCallBack);
	}

	return specialtyBags;
});